<%-- 
    Document   : index
    Created on : 18/03/2011, 21:03:11
    Author     : andre
--%>

<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<jsp:useBean id="contato" scope="request" class="classes.Contato" />
<jsp:useBean id="daoContato" scope="request" class="classesDAO.DAOContato" />
<jsp:setProperty name="contato" property="*"/>
<%@include  file="verificasessao.jspf" %>
<%@include  file="logado.jspf" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%
 int id=0;
  String op="";
  String v_alterou="";
  String action="index.jsp?id=0&op=novo";

  if((request.getParameter("id")!=null)&&(request.getParameter("id")!=""))
       id= Integer.parseInt(request.getParameter("id"));

  if(request.getParameter("op")!=null)
        op= request.getParameter("op");

  if((id>0)&&(op.equals("editar"))){
      contato= daoContato.getContatoPorId(id);
      v_alterou="sim";
      action="index.jsp?v_alterou="+v_alterou;
   }
   if((request.getParameter("v_alterou")!=null)&&(request.getParameter("v_alterou").equals("sim"))){
       daoContato.alterar(contato);
       response.sendRedirect("listacontatos.jsp");

   }

  if((id==0)&&(op.equals("novo"))){
     daoContato.gravar(contato);
     response.sendRedirect("listacontatos.jsp");
   }
  
%>
<html>
    <head>
       <title>Cadastro de Contatos</title>
    </head>
    <body>
        <form action="<%=action%>" method="post">
            <h1>Cadastro de Contatos</h1>
            <p>Nome<input type="text" name="nome" value="<%=contato.getNome()%>" size="50"/></p>
            <p>Telefone<input type="text" name="telefone" value="<%=contato.getTelefone()%>" size="15" /></p>
            <p>id<input type="text" name="idContato" value="<%=contato.getIdContato()%>" size="10" /></p>
            <p><input type="submit" value="Gravar" name="brGravar" /></p>
        
        </form>

    </body>
</html>
